package com.demo07;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @author leebin
 */
public class FileUtilsHelper {
    public static void write(String filePath, String line) {
        try {
            FileUtils.write(new File(filePath), line, "utf-8", true);
            FileUtils.write(new File(filePath), "\r\n", "utf-8", true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void write(File file, String line) {
        try {
            FileUtils.write(file, line, "utf-8", true);
            FileUtils.write(file, "\r\n", "utf-8", true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static List<String> readLines(File file, String encoding) {
        List<String> res = null;
        try {
            res = FileUtils.readLines(file, encoding);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res;
    }
}